type Seq[T] native  // rt.Seq
type List[T] native  // rt.List, ([] T)
type Set[T] native  // rt.Set
type Map[K,V] native  // rt.Map


// Seq

public function variadic
    Seq[T] { list List[T] } Seq[T]
    native('__ListToSeq')

public function
    SeqCount { n Int } Seq[Int]
    native('__SeqCount')

public method
    Seq.List List[T]
    native('__SeqToList')

public method
    Seq.Empty Bool
    { not(Shift(this).Bool) }

public function
    Shift[T] { s Seq[T] } Maybe[Pair[T,Seq[T]]]
    native('__SeqShift')

public function
    Cons[T] { head T, tail Seq[T] } Seq[T]
    native('__SeqCons')

public operator
    reverse[T] { l Seq[T] } Seq[T]
    native('__SeqReverse')

public operator
    prepend[T] { tail Seq[T], head T } Seq[T]
    { Cons(head,tail) }

public operator
    map[A,B] { s Seq[A], f Lambda[A,B] } Seq[B]
    native('__SeqMap')

public operator
    deflate-map[A,B] { s Seq[A], f Lambda[A,Maybe[B]] } Seq[B]
    native('__SeqDeflateMap')

public operator
    flat-map[A,B] { s Seq[A], f Lambda[A,Seq[B]] } Seq[B]
    native('__SeqFlatMap')

public operator
    filter[T] { s Seq[T], f Lambda[T,Bool] } Seq[T]
    native('__SeqFilter')

public operator
    scan[T,A] { s Seq[T], a A, f Lambda[Pair[A,T],A] } Seq[A]
    native('__SeqScan')

public operator
    reduce[T,A] { s Seq[T], a A, f Lambda[Pair[A,T],A] } A
    native('__SeqReduce')

public operator
    apply-all[T] { v T, fs Seq[Lambda[T,T]] } T
    { fs | reduce (v, { (v,f) => f(v) }) }

public operator
    some[T] { s Seq[T], f Lambda[T,Bool] } Bool
    native('__SeqSome')

public operator
    every[T] { s Seq[T], f Lambda[T,Bool] } Bool
    native('__SeqEvery')

public operator
    find-first[T] { s Seq[T], f Lambda[T,Bool] } Maybe[T]
    native('__SeqFindFirst')

public operator
    get-first[T,X] { s Seq[T], f Lambda[T,Maybe[X]] } Maybe[X]
    native('__SeqGetFirst')

public operator
    with-index[T] { s Seq[T] } Seq[Pair[T,Int]]
    native('__SeqWithIndex')

public operator
    chunk[T] { s Seq[T], n Int } Seq[List[T]]
    native('__SeqChunk')

public operator
    concat[T] { a Seq[T], b Seq[T] } Seq[T]
    native('__SeqConcat')

public operator
    zip[A,B] { a Seq[A], b Seq[B] } Seq[Pair[A,B]]
    native('__SeqZip')

public operator
    zip-longest[A,B] { a Seq[A], b Seq[B] } Seq[Pair[Maybe[A],Maybe[B]]]
    native('__SeqZipLongest')

public function
    Zip[T] { all List[Seq[T]] } Seq[List[T]]
    native('__SeqZipList')

public function
    ZipLongest[T] { all List[Seq[T]] } Seq[List[Maybe[T]]]
    native('__SeqZipLongestList')


// List

public function variadic
    List[T] { l List[T] } List[T]
    { l }

public method
    List.Seq Seq[T]
    native('__ListToSeq')

public method
    List.Length Int
    native('__ListLength')

public method
    List.Empty Bool
    native('__ListEmpty')


// Set

public function variadic
    Set[T] { values List[T] } { <> <>[T] } Set[T]
    native('__Set')

public method
    Set.List List[T]
    native('__SetValues')

public operator
    in[T] { v T, s Set[T] }  Bool
    native('__SetHas')

public operator
    not-in[T,S] { v T, s S } { in Lambda[Pair[T,S],Bool] } Bool
    { not(in(v,s)) }


// Map

public function variadic
    Map[K,V] { entries List[Pair[K,V]] } { <> <>[K] } Map[K,V]
    native('__Map')

public method
    Map.List List[Pair[K,V]]
    native('__MapEntries')

public operator
    in[K,V] { key K, m Map[K,V] } Bool
    { (m get key).Bool }

public operator
    get[K,V] { m Map[K,V], key K } Maybe[V]
    native('__MapLookup')

public operator
    insert[K,V] { m Map[K,V], entry Pair[K, V] } Map[K,V]
    native('__MapInsert')

public operator
    delete[K,V] { m Map[K,V], key K } Map[K,V]
    native('__MapDelete')


